﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Controls;
//using GeoDatabase.Library; 
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.DataSourcesRaster;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Geometry;




namespace MyGISapp
{
    public partial class mainForm : Form
    {
        public mainForm()
        {
            InitializeComponent();
        }
        # region  打开地图文档
        private void 打开地图文档ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ////F1 我的
            //try
            //{
            //    //实例化一个对象
            //    OpenFileDialog open = new OpenFileDialog();
            //    //设置参数
            //    //检查文件是否存在
            //    open.CheckFileExists = true;
            //    open.Title = "打开地图文档";
            //    // 不允许多个文件同时打开
            //    open.Multiselect = false;
            //    // 存储时打开的文件路径
            //    open.RestoreDirectory = true;
            //    //打开文件格式
            //    open.Filter = "地图文档(*.mxd)|*.mxd;|ArcMap模板(*.mxt)|*.mxt;|所有地图格式(*.mxd;*.mxt;*.pmf)|*.mxd;*.mxt;*.pmf";//文件过滤条件
            //    open.Multiselect = false;//禁止多选
            //    open.RestoreDirectory = true;  // 存储打开的文件路径
            //    //判断如果文件正常打开
            //    if (open.ShowDialog() == DialogResult.OK)
            //    {
            //        // 获取文件路径  path+name
            //        string fileName = open.FileName;
            //        // 数据窗口加载地图文档
            //        mainMapControl.LoadMxFile(fileName);
            //        // 刷新一下页面
            //        mainMapControl.ActiveView.Refresh();
            //        // 伙伴控件可以通过下面的方式来进行绑定
            //        mainTOCControl.SetBuddyControl(mainMapControl);

            //    }
            //}
            //catch (Exception)
            //{
            //    MessageBox.Show("请打开正确的文档!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //}


            //F2 第一种  使用 LoadMxFile方法  
            //OpenFileDialog open = new OpenFileDialog();
            ////设置参数
            ////检查文件是否存在
            //open.CheckFileExists = true;
            //open.Title = "打开地图文档";
            //// 不允许多个文件同时打开
            //open.Multiselect = false;
            //// 存储时打开的文件路径
            //open.RestoreDirectory = true;
            ////打开文件格式
            //open.Filter = "地图文档(*.mxd)|*.mxd;|ArcMap模板(*.mxt)|*.mxt;|所有地图格式(*.mxd;*.mxt;*.pmf)|*.mxd;*.mxt;*.pmf";//文件过滤条件
            //open.Multiselect = false;//禁止多选
            //open.RestoreDirectory = true;  // 存储打开的文件路径
            //open.ShowDialog();
            ////文件名
            //string fileName = open.FileName;

            //if (fileName == "")
            //{
            //    return;
            //}
            ////检查地图文档有效性
            //if (mainMapControl.CheckMxFile(fileName))
            //{
            //    mainMapControl.LoadMxFile(fileName);
            //    mainMapControl.ActiveView.Refresh();

            //}
            //else
            //{
            //    MessageBox.Show(fileName + "是无效的地图文档!", "信息提示");
            //    return;
            //}



            ////F3 使用IMapDocument接口
            //OpenFileDialog open = new OpenFileDialog();
            //设置参数
            //检查文件是否存在
            //open.CheckFileExists = true;
            //open.Title = "打开地图文档";
            // 不允许多个文件同时打开
            //open.Multiselect = false;
            // 存储时打开的文件路径
            //open.RestoreDirectory = true;
            //打开文件格式
            //open.Filter = @"地图文档(*.mxd)|*.mxd;|ArcMap模板(*.mxt)|*.mxt;|所有地图格式(*.mxd;*.mxt;*.pmf)|*.mxd;*.mxt;*.pmf";//文件过滤条件
            //open.Multiselect = false;//禁止多选
            //open.RestoreDirectory = true;
            //打开窗口
            //open.ShowDialog();
            // 存储打开的文件路径
            //string fileName = open.FileName;
            //if (mainMapControl.CheckMxFile(fileName))
            //{
            //    将数据载入pMapDocument并与Map控件关联
            //    IMapDocument pMapDocument = new MapDocument();   // using ESRI.ArcGIS.Carto;
            //    pMapDocument.Open(fileName, "");
            //    获取Map地图中激活的地图文档
            //    mainMapControl.Map = pMapDocument.ActiveView.FocusMap;
            //    mainMapControl.ActiveView.Refresh();
            //}

            // F4  使用ControlsOpenDocCommandClass
            ICommand command = new ControlsOpenDocCommandClass();    //using ESRI.ArcGIS.Controls;
            command.OnCreate(mainMapControl.Object);
            command.OnClick();
            mainTOCControl.SetBuddyControl(mainMapControl);

            
               
        }
        #endregion

        #region 加载shapefile数据
        private void loadShapeToolStrip_Click(object sender, EventArgs e)
        {
            //F1 自己的方法 AddShapeFile
            try
            {
                OpenFileDialog open = new OpenFileDialog();
                //设置参数
                //检查文件是否存在
                open.CheckFileExists = true;
                open.Title = "打开Shape文件";
                // 存储时打开的文件路径
                open.RestoreDirectory = true;
                //打开文件格式
                open.Filter = "Shape文件(*.shp)|**.shp";   //文件过滤条件
                open.RestoreDirectory = true;  // 存储打开的文件路径

                if (open.ShowDialog() == DialogResult.OK)
                {
                    //首先定义一个空的路径
                    string filePath = string.Empty;
                    //然后定义一个空的文件名
                    string file = string.Empty;
                    //获取完整的文件路径 :path+name
                    string fileDir = open.FileName;
                    if (fileDir == "") return;
                    // 对完整路径进行截取  获取最后一个斜杠的索引
                    int pos = fileDir.LastIndexOf("\\");
                    //截取字符串  路径
                    filePath = fileDir.Substring(0, pos);
                    //文件名
                    file = fileDir.Substring(pos + 1);
                    //需要两个参数
                    mainMapControl.AddShapeFile(filePath, file);
                    mainMapControl.ActiveView.Refresh();
                    //Tooc不知道为啥不能绑定了，还是手动绑定吧
                    mainTOCControl.SetBuddyControl(mainMapControl);

                }

            }
            catch (Exception)
            {
                MessageBox.Show("请打开正确的Shape文件", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }



            // F2 使用工作空间
            //OpenFileDialog open = new OpenFileDialog();
            //open.CheckFileExists = true;
            //open.Title = "打开Shape文件";
            //open.RestoreDirectory = true;
            //open.Filter = "Shape文件(*.shp)|**.shp";
            //open.RestoreDirectory = true;
            //open.ShowDialog();

            ////获取完整的文件路径 :path+name
            //string fileDir = open.FileName;
            ////路径为空不返回
            //if (fileDir == "") return;
            //// 对完整路径进行截取  
            //int pos = fileDir.LastIndexOf("\\");
            ////  路径
            //string pfilePath = fileDir.Substring(0, pos);
            ////文件名
            //string file = fileDir.Substring(pos + 1);

            ////实例化ShapefileWorkspaceFactory工作空间，打开Shape文件
            //IWorkspaceFactory pWsFactory = new ShapefileWorkspaceFactoryClass();
            ////强制转换   打开路径
            //IFeatureWorkspace pWorkSpace = pWsFactory.OpenFromFile(pfilePath, 0) as IFeatureWorkspace;
            ////创建并实例化要素类
            //IFeatureClass pFeatureClass = pWorkSpace.OpenFeatureClass(file);
            //IFeatureLayer pFeatureLayer = new FeatureLayerClass();
            //pFeatureLayer.Name = pFeatureClass.AliasName;
            //pFeatureLayer.FeatureClass = pFeatureClass;

            //mainMapControl.Map.AddLayer(pFeatureLayer);
            //mainMapControl.ActiveView.Refresh();
            //mainTOCControl.SetBuddyControl(mainMapControl);

        }
        #endregion


        #region 加载栅格数据
        private void loadGridToolStrip_Click(object sender, EventArgs e)
        {
            //F1
            OpenFileDialog pOpenFileDialog = new OpenFileDialog();
            pOpenFileDialog.CheckFileExists = true;
            pOpenFileDialog.Title = "加载栅格数据";
            pOpenFileDialog.Filter = "栅格文件(*.*)|*.bmp;*.tif;*.jpg;*.img;|BMP(*.bmp)|*.bmp;|TIF(*.tif)|*.tif;|JPG(*.jpg)|*.jpg;|IMG(*.img)|*.img";
            pOpenFileDialog.ShowDialog();
            //获取名字
            string pRasterFilename = pOpenFileDialog.FileName;
            if (pRasterFilename == "") return;
            // IO里面获取文件名字与路径的固定用法
            string pPath = System.IO.Path.GetDirectoryName(pRasterFilename);
            string pFileName = System.IO.Path.GetFileName(pRasterFilename);

            IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactory();
            IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(pPath, 0);
            IRasterWorkspace pRasterWorkspace = pWorkspace as IRasterWorkspace;
            IRasterDataset pRasterDataset = pRasterWorkspace.OpenRasterDataset(pFileName);
            //影像金字塔的判断与创建
            IRasterPyramid3 pRasPyramid;
            pRasPyramid = pRasterDataset as IRasterPyramid3;
            if (pRasPyramid != null)
            {
                if (!(pRasPyramid.Present))
                { 
                    //创建金字塔
                    pRasPyramid.Create();
                }
            }

            IRaster pRaster;
            pRaster = pRasterDataset.CreateDefaultRaster();
            IRasterLayer pRasterLayer;
            pRasterLayer = new RasterLayerClass();
            pRasterLayer.CreateFromRaster(pRaster);
            ILayer pLayer = pRasterLayer as ILayer;
            mainMapControl.AddLayer(pLayer, 0);


            //F2
           


        }
        #endregion

        #region 加载CAD数据 
        private void loadCadToolStrip_Click(object sender, EventArgs e)
        {
            OpenFileDialog pOpenFileDialog = new OpenFileDialog();
            pOpenFileDialog.CheckFileExists = true;
            pOpenFileDialog.Title = "加载CAD数据";
            pOpenFileDialog.Filter = "栅格文件(*.dwg)|*.dwg";
            pOpenFileDialog.ShowDialog();
            //获取名字
            string pFullFilename = pOpenFileDialog.FileName;
            if (pFullFilename == "") return;
            //获取路径和文件名
            string pPath = System.IO.Path.GetDirectoryName(pFullFilename);
            string pFileName = System.IO.Path.GetFileName(pFullFilename);

            //// F1.作为矢量图层加载  === 1)分图层加载
            IWorkspaceFactory pWorkspaceFactory;
            IFeatureWorkspace pFeatureWorkspace;
            pWorkspaceFactory = new CadWorkspaceFactory();
            pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(pPath, 0);
            //加载CAD文件中的线文件
            IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(pFileName + ":polyline");
            IFeatureLayer pFeatureLayer = new FeatureLayerClass();
            pFeatureLayer.Name = pFileName;
            pFeatureLayer.FeatureClass = pFeatureClass;
            mainMapControl.Map.AddLayer(pFeatureLayer);
            mainMapControl.ActiveView.Refresh();
            mainTOCControl.SetBuddyControl(mainMapControl);


            // F2.作为矢量图层加载  === 2)整图加载
            ////打开CAD数据集
            //IWorkspaceFactory pWorkspaceFactory = new CadWorkspaceFactoryClass();  //using ESRI.ArcGIS.DataSourcesFile;
            //IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(pPath, 0) as IFeatureWorkspace;
            ////打开一个要素集
            //IFeatureDataset pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(pFileName);
            //// IFeatureContainer可以管理IFeatureDataset中的每个要素类
            //IFeatureClassContainer pFeatureContainer = (IFeatureClassContainer)pFeatureDataset;
                
            ////对CAD文件中的要素进行遍历处理
            //for (int i = 0; i < pFeatureContainer.ClassCount; i++)
            //{
            //    IFeatureClass pFeatureClass = pFeatureContainer.get_Class(i);
            //    //如果是注记， 则添加注记层
            //    if (pFeatureClass.FeatureType == esriFeatureType.esriFTCoverageAnnotation)
            //    {
            //        IFeatureLayer pFeatureLayer = new FeatureLayerClass();
            //        pFeatureLayer.Name = pFeatureClass.AliasName;
            //        pFeatureLayer.FeatureClass = pFeatureClass;
            //        mainMapControl.Map.AddLayer(pFeatureLayer);       
            //    }
            //    else  //如果是点线面则添加要素层
            //    {
            //        IFeatureLayer pFeatureLayer = new FeatureLayerClass();
            //        pFeatureLayer.Name = pFeatureClass.AliasName;
            //        pFeatureLayer.FeatureClass = pFeatureClass;
            //        mainMapControl.Map.AddLayer(pFeatureLayer);

            //     }
            //    mainMapControl.ActiveView.Refresh();
            //    mainTOCControl.SetBuddyControl(mainMapControl);
            //}


            // F3.作为栅格图层加载 
            //IWorkspaceFactory pWorkspaceFactory;
            //IWorkspace pWorkspace;
            //ICadDrawingDataset pCadDrawingDataset;
            //ICadDrawingWorkspace pCadDrawingWorkspace;
            //ICadLayer pCadLayer;

            //pWorkspaceFactory = new CadWorkspaceFactoryClass();
            //pWorkspace = pWorkspaceFactory.OpenFromFile(pPath, 0);
            //pCadDrawingWorkspace = (ICadDrawingWorkspace)pWorkspace;
            ////获得CAD文件的数据集
            //pCadDrawingDataset = pCadDrawingWorkspace.OpenCadDrawingDataset(pFileName);
            //pCadLayer = new CadLayerClass();
            //pCadLayer.CadDrawingDataset = pCadDrawingDataset;
            //mainMapControl.Map.AddLayer(pCadLayer);
            //mainMapControl.ActiveView.Refresh();
            //mainTOCControl.SetBuddyControl(mainMapControl);


        }
        #endregion

        #region 加载SDE
        private void loadSDEToolStrip_Click(object sender, EventArgs e)
        {
            MessageBox.Show("此功能待开发!还有10S...请火速离开！","友情提示",MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        #endregion

        #region AddAllDataset函数
        //封装加载空间数据库方法：AddAllDataset函数，以便对其他空间数据库加载时直接调用。
        private void AddAllDataset(IWorkspace pWorkspace, AxMapControl mapControl)
        {
            IEnumDataset pEnumDataset = pWorkspace.get_Datasets(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTAny);
            pEnumDataset.Reset();
            //将Enum数据集集中的数据一个一个地读到dataset 中
            IDataset pDataset = pEnumDataset.Next();
            //判断数据集是否有数据
            while (pDataset != null)
            {
                if (pDataset is IFeatureDataset)//要素数据集
                {
                    IFeatureWorkspace pFeatureWorkspac = (IFeatureWorkspace)pWorkspace;
                    IFeatureDataset pFeatureDataset = pFeatureWorkspac.OpenFeatureDataset(pDataset.Name);
                    IEnumDataset pEnumDataset1 = pFeatureDataset.Subsets;
                    pEnumDataset1.Reset();
                    IGroupLayer pGroupLayer = new GroupLayerClass();
                    pGroupLayer.Name = pFeatureDataset.Name;
                    IDataset pDataset1 = pEnumDataset1.Next();
                    while (pDataset1 != null)
                    {
                        if (pDataset1 is IFeatureClass)//要素类
                        {
                            IFeatureLayer pFeatureLayer = new FeatureLayerClass();
                            pFeatureLayer.FeatureClass = pFeatureWorkspac.OpenFeatureClass(pDataset1.Name);
                            if (pFeatureLayer.FeatureClass != null)
                            {
                                pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
                                pGroupLayer.Add(pFeatureLayer);
                                mapControl.Map.AddLayer(pFeatureLayer);
                            }
                        }
                        pDataset1 = pEnumDataset1.Next();
                    }
                }
                else if (pDataset is IFeatureClass)//要素类
                {
                    IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspace;
                    IFeatureLayer pFeatureLayer = new FeatureLayerClass();
                    pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(pDataset.Name);
                    pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
                    mapControl.Map.AddLayer(pFeatureLayer);
                }
                else if (pDataset is IRasterDataset)//栅格数据
                {
                    IRasterWorkspaceEx pRasterWorkspace = (IRasterWorkspaceEx)pWorkspace;
                    IRasterDataset pRasterDataset = pRasterWorkspace.OpenRasterDataset(pDataset.Name);
                    //影像金字塔的判断和创建
                    IRasterPyramid3 pRasterPyramid;
                    pRasterPyramid = pRasterDataset as IRasterPyramid3;
                    if (pRasterPyramid != null)
                    {
                        if (!(pRasterPyramid.Present))
                        {
                            pRasterPyramid.Create();//创建金字塔
                        }
                    }
                    IRasterLayer pRasterLayer = new RasterLayerClass();
                    pRasterLayer.CreateFromDataset(pRasterDataset);
                    ILayer pLayer = pRasterLayer as ILayer;//进行继承
                    mapControl.AddLayer(pLayer, 0);
                }
                pDataset = pEnumDataset.Next();
            }
            mapControl.ActiveView.Refresh();
            //同步鹰眼
            // SynchronizeEagleEye();
        }
        #endregion

        #region 加载个人数据库
        private void loadGdbToolStrip_Click(object sender, EventArgs e)
        {
            OpenFileDialog pOpenFileDialog = new OpenFileDialog();
            pOpenFileDialog.CheckFileExists = true;
            pOpenFileDialog.Title = "加载个人数据库";
            pOpenFileDialog.Filter = "个人数据库(*.mdb)|*.mdb";
            pOpenFileDialog.ShowDialog();
            //获取名字
            string pFullPath = pOpenFileDialog.FileName;

            AccessWorkspaceFactory pAccessWorkspaceFactory = new AccessWorkspaceFactory(); //using ESRI.ArcGIS.DataSourcesGDB;
            IWorkspace pWorkspace = pAccessWorkspaceFactory.OpenFromFile(pFullPath, 0);
            //加载工作空间里面的数据
            AddAllDataset(pWorkspace, mainMapControl);
            mainTOCControl.SetBuddyControl(mainMapControl);
        }
        #endregion

        #region 加载文件数据库
        private void loadMdbToolStrip_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dlg = new FolderBrowserDialog();
            if (dlg.ShowDialog() != DialogResult.OK) return;
            string pFullPath = dlg.SelectedPath;
            if (pFullPath == "")
            {
                return;  
            }
            //using ESRI.ArcGIS.DataSourcesGDB;
            IWorkspaceFactory pFileGDBWorkspaceFactory = new FileGDBWorkspaceFactoryClass();
            //获取工作空间
            IWorkspace pWorkspace = pFileGDBWorkspaceFactory.OpenFromFile(pFullPath, 0);
            AddAllDataset(pWorkspace, mainMapControl);
            mainTOCControl.SetBuddyControl(mainMapControl);


        }
        #endregion


        struct CPoint
        {
            public string Name;
            public double X;
            public double Y;
        }

        private List<CPoint> GetPoints(string surveyDataFullName)
        {
            try
            {
                List<string> pColumns = new List<string>();
                List<CPoint> pList = new List<CPoint>();
                //常用分隔符为逗号，空格，制位符
                char[] charArray = new char[] { ',', ' ', '\t' };
                //文本信息读取
                System.IO.FileStream fs = new System.IO.FileStream(surveyDataFullName, FileMode.Open);
                StreamReader sr = new StreamReader(fs, Encoding.Default);
                string strLine = sr.ReadLine();
                if (strLine != null)
                {
                    string[] strArray = strLine.Split(charArray);
                    if (strArray.Length > 0)
                    {
                        for (int i = 0; i < strArray.Length; i++)
                        {
                            pColumns.Add(strArray[i]);
                        }
                    }
                    while ((strLine = sr.ReadLine()) != null)
                    {
                        //点信息的读取
                        strArray = strLine.Split(charArray);
                        CPoint pCPoint = new CPoint();
                        pCPoint.Name = strArray[0].Trim();
                        pCPoint.X = Convert.ToDouble(strArray[1]);
                        pCPoint.Y = Convert.ToDouble(strArray[2]);
                        pList.Add(pCPoint);
                    }
                }
                else
                {
                    return null;
                }
                sr.Close();
                return pList;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
            }
        }

        private IFeatureLayer CreateShpFromPoints(List<CPoint> cPointList, string filePath)
        {
            // using ESRI.ArcGIS.Geometry;
            int index = filePath.LastIndexOf('\\');
            string folder = filePath.Substring(0, index);
            string shapeName = filePath.Substring(index + 1);
            IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pFWS = (IFeatureWorkspace)pWSF.OpenFromFile(folder, 0);

            IFields pFields = new FieldsClass();
            IFieldsEdit pFieldsEdit;
            pFieldsEdit = (IFieldsEdit)pFields;

            IField pField = new FieldClass();
            IFieldEdit pFieldEdit = (IFieldEdit)pField;
            pFieldEdit.Name_2 = "Shape";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
            IGeometryDef pGeometryDef = new GeometryDefClass();
            IGeometryDefEdit pGDefEdit = (IGeometryDefEdit)pGeometryDef;
            pGDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
            //定义坐标系
            ISpatialReferenceFactory pSRF = new SpatialReferenceEnvironmentClass();
            ISpatialReference pSpatialReference = pSRF.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);
            pGDefEdit.SpatialReference_2 = pSpatialReference;

            pFieldEdit.GeometryDef_2 = pGeometryDef;
            pFieldsEdit.AddField(pField);

            IFeatureClass pFeatureClass;
            pFeatureClass = pFWS.CreateFeatureClass(shapeName, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");

            IPoint pPoint = new PointClass();
            for (int j = 0; j < cPointList.Count; j++)
            {
                pPoint.X = cPointList[j].X;
                pPoint.Y = cPointList[j].Y;

                IFeature pFeature = pFeatureClass.CreateFeature();
                pFeature.Shape = pPoint;
                pFeature.Store();
            }

            IFeatureLayer pFeatureLayer = new FeatureLayerClass();
            pFeatureLayer.Name = shapeName;
            pFeatureLayer.FeatureClass = pFeatureClass;
            return pFeatureLayer;
        }

        #region 打开文本文件
        private void loadTxtToolStrip_Click(object sender, EventArgs e)
        {
            string txtSource;
            string txtSave;
            OpenFileDialog pOpenFileDialog = new OpenFileDialog();
            pOpenFileDialog.CheckFileExists = true;
            pOpenFileDialog.Title = "打开txt文件";
            pOpenFileDialog.Filter = "文件(*.txt)|*.txt";
            pOpenFileDialog.ShowDialog();
            txtSave = pOpenFileDialog.FileName;
            pOpenFileDialog.FileName = System.IO.Path.GetFileNameWithoutExtension(txtSave);
            txtSource = pOpenFileDialog.FileName;
            List<CPoint> pCPointList = GetPoints(txtSave);
            if (pCPointList == null)
            {
                MessageBox.Show("所选择的文件为空，请重新选择！");
            }
            else
            {
                //实例化要素图层，进行添加
                IFeatureLayer pFeatureLayer = CreateShpFromPoints(pCPointList, txtSave);//传入实参数据
                mainMapControl.Map.AddLayer(pFeatureLayer);
                mainTOCControl.SetBuddyControl(mainMapControl);

            }
        }
        #endregion

        #region 保存地图文档
        private void saveToolStrip_Click(object sender, EventArgs e)
        {

        }
        #endregion

        #region 另存为地图文档
        private void saveAsToolStrip_Click(object sender, EventArgs e)
        {

        }
        #endregion


    }
         

    }

